<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">用户管理</ui:define>
    <ui:define name="content">
        <h:form>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix"
                 style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton value="批量模式"
                                         icon="fa fa-list-ul"
                                         actionListener="#{systemUserListBean.changeModeToBatch}"
                                         update="@form"
                                         process="@this"
                                         rendered="#{systemUserListBean.isNotBatch()}"/>
                        <p:commandButton value="常规模式" icon="fa fa-file"
                                         actionListener="#{systemUserListBean.changeModeToNormal}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{systemUserListBean.isBatch()}"/>
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"
                                         rendered="#{security:areAllGranted('USER_SEARCH')}"/>
                        <p:columnToggler datasource="userDataTable" trigger="toggler"
                                         rendered="#{security:areAllGranted('USER_SEARCH')}"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         update="@form"
                                         rendered="#{systemUserListBean.isNormal() and security:areAllGranted('USER_SEARCH')}"/>
                        <p:commandButton value="重置" icon="fa fa-refresh"
                                         actionListener="#{systemUserListBean.onReset}"
                                         process="@this"
                                         update="@form"
                                         rendered="#{systemUserListBean.isNormal() and security:areAllGranted('USER_SEARCH')}"/>
                        <p:commandButton value="启用" icon="fa fa-play"
                                         actionListener="#{systemUserListBean.onBatchEnable}"
                                         update="@form"
                                         rendered="#{systemUserListBean.isBatch() and security:areAllGranted('USER_ENABLE')}"/>
                        <p:commandButton value="禁用" icon="fa fa-warning"
                                         actionListener="#{systemUserListBean.onBatchDisable}"
                                         update="@form"
                                         rendered="#{systemUserListBean.isBatch() and security:areAllGranted('USER_DISABLE')}"/>
                        <p:commandButton icon="fa fa-plus" value="新增"
                                         action="#{systemUserListBean.onAdd}"
                                         rendered="#{systemUserListBean.isNormal() and security:areAllGranted('USER_ADD')}">
                            <f:setPropertyActionListener value="/views/system/user/user-list.xhtml"
                                                         target="#{currentUserBean.back}"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-fluid" style="padding-top: 30px;">
                <div class="ui-g">
                    <div class="ui-g-12">
                        <div class="card">
                            <h1>查询条件</h1>
                            <p:panelGrid columns="8" layout="grid"
                                         columnClasses="ui-grid-col-1,ui-grid-col-2"
                                         styleClass="ui-panelgrid-blank"
                                         style="border:0px none; background-color:transparent;">
                                <p:outputLabel for="name" value="姓名"/>
                                <p:inputText id="name" value="#{systemUserListBean.$.name}"/>

                                <p:outputLabel for="account" value="用户名"/>
                                <p:inputText id="account" value="#{systemUserListBean.$.account}"/>

                                <p:outputLabel for="email" value="邮箱"/>
                                <p:inputText id="email" value="#{systemUserListBean.$.email}"/>

                                <p:outputLabel for="phone" value="联系电话"/>
                                <p:inputText id="phone" value="#{systemUserListBean.$.phone}"/>

                                <p:outputLabel for="partner" value="合作机构"/>
                                <p:selectOneMenu id="partner" value="#{systemUserListBean.$.partnerId}" filter="true"
                                                 filterMatchMode="contains">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems value="#{systemUserListBean.partners}" var="partner"
                                                   itemLabel="#{partner.name}" itemValue="#{partner.id}"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="enable" value="是否启用"/>
                                <p:selectOneMenu id="enable" value="#{systemUserListBean.$.enable}">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItem itemLabel="是" itemValue="true"/>
                                    <f:selectItem itemLabel="否" itemValue="false"/>
                                </p:selectOneMenu>

                                <p:outputLabel for="locked" value="是否锁定"/>
                                <p:selectOneMenu id="locked" value="#{systemUserListBean.$.locked}">
                                    <f:selectItem itemLabel="- 请选择 -" itemValue="" noSelectionOption="true"/>
                                    <f:selectItem itemLabel="是" itemValue="true"/>
                                    <f:selectItem itemLabel="否" itemValue="false"/>
                                </p:selectOneMenu>

                            </p:panelGrid>
                        </div>
                        <div class="card">
                            <p:dataTable id="userDataTable"
                                         style="width: 100%"
                                         var="user"
                                         value="#{systemUserListBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection="#{systemUserListBean.selectedRecords}"
                                         resizableColumns="true"
                                         rendered="#{security:areAllGranted('USER_SEARCH')}">

                                <p:column headerText="操作" rendered="#{systemUserListBean.isNotBatch()}">
                                    <p:splitButton icon="fa fa-eye" action="#{systemUserListBean.onEdit(user.id)}"
                                                   process="@this">
                                        <f:setPropertyActionListener value="/views/system/user/user-list.xhtml"
                                                                     target="#{currentUserBean.back}"/>
                                        <p:menuitem value="启用" icon="fa fa-play"
                                                    action="#{systemUserListBean.onEnable(user.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{!user.enable and security:areAllGranted('USER_ENABLE')}"/>

                                        <p:menuitem value="禁用" icon="fa fa-warning"
                                                    actionListener="#{systemUserListBean.onDisable(user.id)}"
                                                    process="@this" update="@form"
                                                    rendered="#{user.enable and security:areAllGranted('USER_DISABLE')}">
                                        </p:menuitem>

                                        <p:menuitem value="关联角色" icon="fa fa-graduation-cap"
                                                    action="#{systemUserListBean.onRelateRole(user.id)}"
                                                    rendered="#{security:areAllGranted('USER_RELATE_ROLE')}">
                                            <f:setPropertyActionListener value="/views/system/user/user-list.xhtml"
                                                                         target="#{currentUserBean.back}"/>
                                        </p:menuitem>

                                        <p:menuitem value="分配权限" icon="fa fa-sitemap"
                                                    action="#{systemUserListBean.onRelatePermission(user.id)}"
                                                    rendered="#{security:areAllGranted('USER_RELATE_PERMISSION')}">
                                            <f:setPropertyActionListener value="/views/system/user/user-list.xhtml"
                                                                         target="#{currentUserBean.back}"/>
                                        </p:menuitem>

                                        <p:menuitem value="重置密码" icon="fa fa-rotate-left"
                                                    actionListener="#{systemUserListBean.onResetPassword(user.id)}"
                                                    rendered="#{security:areAllGranted('USER_RESET_PASSWORD')}"/>

                                        <p:menuitem value="解除锁定" icon="fa fa-unlock"
                                                    actionListener="#{systemUserListBean.unlock(user.id)}" update="@form"
                                                    rendered="#{user.locked and security:areAllGranted('USER_UNLOCK')}"/>
                                    </p:splitButton>
                                </p:column>
                                <p:column selectionMode="multiple" style="width:16px;text-align:center"
                                          rendered="#{systemUserListBean.isBatch()}"/>

                                <p:column headerText="姓名">
                                    <h:outputText value="#{user.name}"/>
                                </p:column>
                                <p:column headerText="账号">
                                    <h:outputText value="#{user.account}"/>
                                </p:column>
                                <p:column headerText="邮箱">
                                    <h:outputText value="#{user.email}"/>
                                </p:column>
                                <p:column headerText="联系电话">
                                    <h:outputText value="#{user.phone}"/>
                                </p:column>
                                <p:column headerText="合作机构">
                                    <h:outputText value="#{user.partnerName}"/>
                                </p:column>
                                <p:column headerText="最后登录时间">
                                    <h:outputText value="#{user.lastLoginTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="是否启用">
                                    <h:outputText value="#{user.enable ? '是' : '否'}"/>
                                </p:column>
                                <p:column headerText="是否锁定">
                                    <h:outputText value="#{user.locked ? '是' : '否'}"/>
                                </p:column>
                            </p:dataTable>
                        </div>
                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>
